class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int ret = INT_MAX;
        int sum = 0;
        int i = 0;
        int len = 0;
        for(int j = 0;j < nums.size();j++){
            sum += nums[j];
            while(sum >= target){
                len = j - i + 1;
                ret = min(ret,len);
                sum -= nums[i++];
            }
        }
        return ret == INT_MAX ? 0 : ret;
    }
};
